User Tools

Site Tools


java:loops:for

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

java:loops:for [2013/04/18 09:01]
88.74.75.6 created
java:loops:for [2024/02/16 01:04] (current)
Line 9: Line 9:
 a for loop do statements while the condition is true/untrue, the increment counts the loop, it is possible to use more than 1 condition in the for loop a for loop do statements while the condition is true/untrue, the increment counts the loop, it is possible to use more than 1 condition in the for loop
  
-===== example of for example 1 in java =====+===== example of for in java =====
 <code java> <code java>
  
Line 40: Line 40:
     i is: 4 <= 5     i is: 4 <= 5
     i is: 5 <= 5     i is: 5 <= 5
-     
  
-  +==== example 2 of for in java ==== 
 +with 2 conditions 
 +<code java> 
 +package codereferececomjava; 
 + 
 +import java.util.Scanner; 
 + 
 +public class CodeRefereceComJava { 
 +  
 +  
 +    public static void main(String[] args) { 
 +         
 +        Scanner keyboard = new Scanner(System.in); 
 +        int passwd=12345; 
 +        int typedIn = 0; 
 +         
 +        // 2 conditions in for loop 
 +        for (int i = 0; i < 3 && passwd != typedIn; i++) { 
 +            System.out.print("please enter 12345 between 3 attempts: " ); 
 +            typedIn = keyboard.nextInt(); 
 +         } 
 +         
 +        if (passwd == typedIn) { 
 +            System.out.println("Success"); 
 +        } else { 
 +            System.out.println("Failure"); 
 +        } 
 + 
 +    } 
 +
 + 
 +</code> 
 + 
 +=== output of for example 2 in java === 
 + 
 +    please enter 12345 between 3 attempts: 42 
 +    please enter 12345 between 3 attempts: 12345 
 +    Success
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
java/loops/for.1366268460.txt · Last modified: 2024/02/16 01:02 (external edit)

Impressum Datenschutz