DEV Community

loading...

Can you have a while loop inside if condition?

whataluckyguy profile image Lalit Kumar ・1 min read

The question we will discuss in this article is “can you have a while loop inside if condition?”
Yes!!! We can have a while loop inside a if condition. The if statement only is condition if that happens then do this otherwise follow the other statement and the while loop is the repetition statement. We can use while loop inside an if statement as a conditional statement.

If statement

Programs use selection statements to choose among other paths of actions. For example: If a student's grade is greater than or equal to 60 then print “passed”. The if statement is a single-entry/exit statement.

While loop

A repetition/loop statement specifies that a program should repeat an action while some condition remains true.

Read more

Discussion

pic
Editor guide
Collapse
snjjay profile image
snjjay

nice one

Collapse
whataluckyguy profile image