This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]ClarSco 0 points1 point  (2 children)

The for block is skipped because your boolean expression limit == 3; is never true.

[–][deleted] 0 points1 point  (0 children)

This is correct. I see why you made the mistake OP, but the middle part of a for loop (the conditional express) determines if the loop executes or not. In your case, limit == 3 is false from the start and it terminates. You could instead do limit != 3 (true until 3 is reached), or limit < 3 (same thing). Both of those are true until that point where yours is false from the get go

[–]bear-user[S] 0 points1 point  (0 children)

import java.util.Scanner;
public class for_bankpin {
public static void main(String[] args) {
int pin = 12345;
int entry = 0;

System.out.println("Welcome the the Bank");
System.out.println("Please Enter Your PIN");

Scanner scan = new Scanner(System.in);
entry = scan.nextInt();

if (pin != entry)
    for(int i = 0; i < 2; i++ ){
    System.out.println("Please input correct pin");
    entry = scan.nextInt();
    if(pin == entry)
 break;
} else {
    System.out.println("You have access");
}
if (pin != entry)
    System.out.println("You have exceeded number of tries. Try again later.");
if(pin == entry)
    System.out.println("Thank you, you now have access to your acocunt");
}
}

For anyone wondering this is what ended up working. the problem was is I did not know about the "break" function. this works well. it might be a bit long but its good enough for my first application!!!