+ 2

I didnā€™t fully understand the topic, or an error during verification?

if put ; The code works but not the way I would like. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for(int i=0; i<n; i++) ; <========here { System.out.println("Welcome"); } } }

1st Jun 2022, 2:42 AM
Rosterik
Rosterik - avatar
2 Answers
+ 5
If you put the semicolon after the loop construct, then the block underneath will not be considered as the loop body, thus there will be only 1 line of "Welcome" printed on screen. If the instruction was to print "Welcome" <n> number of times, then don't put the semicolon after the loop construct.
1st Jun 2022, 2:50 AM
Ipang
+ 1
thank you for your time. I understand
1st Jun 2022, 2:52 AM
Rosterik
Rosterik - avatar