114k views
1 vote
What output is produced by the following code fragment int num = 1 max = 20 while num < max?

1 Answer

2 votes
Firstly, you'd generate a compile error.

I don't know what language you're using, but you need to have a comma before declaring max, to tell the compiler you're creating another variable of type int. Additionally, you didn't end that line with a semi-colon (again, I don't know what language you're using, so this semi-colons could be irrelevant, such as in Python). Finally, a condition in a while loop is usually encapsulated by parentheses, like this "while (num < max)", and braces are introduced if you're creating a while loop greater than 1 statement.

But to answer your question. No output.
User Yitz
by
8.8k points