C
C#•8mo ago
HD-Fr0sT

My methods loop does not want to stop even if i use return

I have tried different ways but i cant get to making it just exit
11 Replies
HD-Fr0sT
HD-Fr0sTOP•8mo ago
using ClassFile;

while (true)
{
Console.Clear();
ClassFile.Class.VisaMeny();

Console.WriteLine("sfdb");

}
using ClassFile;

while (true)
{
Console.Clear();
ClassFile.Class.VisaMeny();

Console.WriteLine("sfdb");

}
main
Pobiega
Pobiega•8mo ago
That loop will indeed never stop
HD-Fr0sT
HD-Fr0sTOP•8mo ago
namespace ClassFile;

public class Class
{
public static int VisaMeny()
{

string punkt = "*";

int val = 1;
int vald = 0;

while (true)
{
Console.Clear();
Console.WriteLine($"{(val == 1 ? punkt : " ")} Val (1) ");
Console.WriteLine($"{(val == 2 ? punkt : " ")} Val (2) ");
Console.WriteLine($"{(val == 3 ? punkt : " ")} Val (3) ");

ConsoleKeyInfo key;
key = Console.ReadKey();

switch (key.Key)
{
case ConsoleKey.DownArrow:
val++;
break;

case ConsoleKey.UpArrow:
val--;
break;

case ConsoleKey.Enter:
val = vald;
return vald;

}


switch (val)
{
case >3:
val = 1;
break;

case <1:
val = 3;
break;
}
}


}
}
namespace ClassFile;

public class Class
{
public static int VisaMeny()
{

string punkt = "*";

int val = 1;
int vald = 0;

while (true)
{
Console.Clear();
Console.WriteLine($"{(val == 1 ? punkt : " ")} Val (1) ");
Console.WriteLine($"{(val == 2 ? punkt : " ")} Val (2) ");
Console.WriteLine($"{(val == 3 ? punkt : " ")} Val (3) ");

ConsoleKeyInfo key;
key = Console.ReadKey();

switch (key.Key)
{
case ConsoleKey.DownArrow:
val++;
break;

case ConsoleKey.UpArrow:
val--;
break;

case ConsoleKey.Enter:
val = vald;
return vald;

}


switch (val)
{
case >3:
val = 1;
break;

case <1:
val = 3;
break;
}
}


}
}
Pobiega
Pobiega•8mo ago
You can't stop that loop from inside VisaMeny
HD-Fr0sT
HD-Fr0sTOP•8mo ago
frick
Pobiega
Pobiega•8mo ago
You will need to inspect the return value from VisaMeny inside your main looo
HD-Fr0sT
HD-Fr0sTOP•8mo ago
can i use continue in main? to skip but it wont work prob
Pobiega
Pobiega•8mo ago
continue; is a loop instruction, it means "start the next iteration of the loop right away" in your main method, that wont do much in fact, why is your main doing while(true)? VisaMeny handles the menu interaction when it returns, the user has selected something if you want to show the same menu again and again until the user picks a certain something, handle that with an if(VisaMeny() == StoppaProgrammet) return;
HD-Fr0sT
HD-Fr0sTOP•8mo ago
i moved stuff from main to the second file and forgot about that
Pobiega
Pobiega•8mo ago
easy fix then 🙂 just remove the outer loop
HD-Fr0sT
HD-Fr0sTOP•8mo ago
i fogor lamo lmao
Want results from more Discord servers?
Add your server