vendredi 25 janvier 2019

Error: not a loop label: until ! please help :/

I'm really confused as to how I can make this work. Every time I've tried to compile this, the compiler throws the exception "Not a loop label: until" & every time I switch up the break & continue statement it doesn't change a thing. I originally started with out the if else statement & even then, I kept getting the same error. Please help me to fix this, & to understand it. PS - I'm new to this & have been coding for just over six months now.

PPS - Is the code messy ? If so where can I learn to type clean efficient code ?

import java.util.Random;

class LabelledContinueDemo1 {
public static void main(String args) {

    Random rand = new Random();
    int number = rand.nextInt(5)+1;
    String possibleoutcome; 
    until: switch(number) { 
    case 1: possibleoutcome = " First outcome randomly picked";
    break;
    case 2: possibleoutcome = "Second outcome randomly picked";
    break;
    case 3: possibleoutcome = "Third outcome randomly picked";
    break;
    case 4: possibleoutcome = "Fourth outcome randomly picked";
    break;
    case 5: possibleoutcome = "Fifth outcome randomly picked";
    break;
    default: possibleoutcome = "Outcome doesn't exist";
    break;

    if (number != 1) { 
    continue until;
    } 

    else {
        break;
    }
    }
    System.out.println(number);
}

}

Aucun commentaire:

Enregistrer un commentaire