-1

flowchart while loop

In the picture above, the control statement is "loopCount < ? 10". What is the correct control statement of this one if written in code? (code should be written in a while loop, java)

"while(loopCount<=10)" or "while(loopCount==10)"?

What does "< ?" mean?

haku
  • 11
  • 1
  • that is a simple conditional statement, hence the possible results: true and false. IF loopCount < 10 THEN perform the true part ELSE perform the false part – Stultuske Sep 26 '22 at 11:47
  • 1
    I don't know what the "?" means. Looks like a mistake / formatting error in the flow chart. About the solution: Think about what your proposed while statements mean. You can read them as if they are almost English and then reason. Hint: Both are wrong. The flowchart asks you to check if loopCount is less than 10, not less-or-equal or equal to 10. – Jesper Sep 26 '22 at 11:48

1 Answers1

1

Q: What does loopCount < ? 10 mean?

It looks to me like a typo. It would make more sense if it was written as:

loopCount < 10 ?

Or in plain English as "is loopCount less that 10?".

The entire flowchart1 can written in Java as a while loop, or a for loop.

However, neither of your attempts is exactly correct. See Jesper's comment.

What you need is a Java loop that performs the "output" with loopCount values 1 through 9 inclusive; i.e. nine times.


1 - You can't translate the flowchart boxes and lines individually and assemble them into valid / working Java. A literal translation would require goto statements for some of the lines, and Java doesn't support that. (Old-school FORTRAN, COBOL and BASIC did!) Instead, you have to extract the meaning of the flowchart, and write Java code that does the same thing.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216