Compare and contrast in your own words a pure counter-controlled for loop with a while loop illustrating your answer using the following example functions. You may assume that the dice function returns an integer between 1 and 6.

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question

Compare and contrast in your own words a pure counter-controlled for loop with a while loop illustrating your answer using the following example functions. You may assume that the dice function returns an integer between 1 and 6. 

public static int gamel ()
{
int count = 0;
int score
0;
while (score < 21)
{
int roll = dice();
score + roll;
= count + 1;
score =
count
}
return count;
}
public static int game2 ()
{
int score = 0;
for(int count=0; count<21; count =
= count + 1)
{
int roll = dice();
score = score + roll;
}
return score;
}
Transcribed Image Text:public static int gamel () { int count = 0; int score 0; while (score < 21) { int roll = dice(); score + roll; = count + 1; score = count } return count; } public static int game2 () { int score = 0; for(int count=0; count<21; count = = count + 1) { int roll = dice(); score = score + roll; } return score; }
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning