Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How to achieve this C# for-loop in IronPython, I can't seem to find a way to make i - 10 in IronPython
int amount = 32;
int scrolls = 0;
int mets = 0;
if (amount >= 10) {
for (int i = amount; i >= 10; i -= 10) {
scrolls++;
if (i - 10 < 10)
mets = i - 10;
}
}
Your loop exit condition is i >= 10. Your loop entry condition is amount >= 10. i gets set to your amount on loop entry, which is already >= 10. Your loop will never execute.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
var input = Convert.ToInt32(Console.ReadLine());
for (var i = 1; i <= input; i++)
{
for (var tr = 1; tr <= input; tr++)
{
for (var ch = 1; ch <= input; ch++)
{
if (ch <= i) Console.Write("+");
else Console.Write(" ");
}
}
Console.WriteLine();
}
The program outputs triangles. The code uses three loops. How to make it so that there are only two loops and the program works the same as before?
Notice in the pattern of triangles that on the first line you print 1 + then print n-1 blanks repeatedly. On the second line you print two + then print n-2 blanks repeatedly.
To decide if you need to print a plus or a blank you can use modulo arithmetics. if c % n < lineno print + else print a blank.
You print n * n characters in each line.
That's not the complete code but a good boost to implement the solution.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Hi everyone I need to generate all strings from aa0000 to zz9999; where the first two position are only chars from a to z and the last four positions are from 0000 to 9999.
I tried everything I could but I can't find a way to do this.
Thanks in advance!
You can try nested loops, e.g.
Code:
public static IEnumerable<string> Generator() {
for (char a = 'a'; a <= 'z'; ++a)
for (char b = 'a'; b <= 'z'; ++b)
for (int i = 0; i <= 9999; ++i)
yield return $"{a}{b}{i:d4}";
}
...
foreach (string s in Generator()) {
//TODO: Put relevant code here
}
Demo:
Console.WriteLine(string.Join(Environment.NewLine, Generator()
.Skip(1_000_000 - 5) // skip some items
.Take(10))); // then take some items
Console.WriteLine();
Console.Write(Generator().Count()); // how many items do we have?
Outcome:
dv9995
dv9996
dv9997
dv9998
dv9999
dw0000
dw0001
dw0002
dw0003
dw0004
6760000
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How do i increment a value by 2 instead of 1? when i run my code it will go from 1-10 by adding 1 but i want it to go 1-10 by adding 2
for (int x=0;x<10;x++)
{
Console.WriteLine(x);
}
You can do instead -
for (int x = 0; x < 10;) {
Console.WriteLine(x);
x = x + 2;
}
If I understand you correctly, this should be the solution for you.
for (int x = 0; x < 10; x += 2)
{
Console.WriteLine(x);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need my if statement to return an image if it is within a range. the current code does not work
if (Int32.Parse(Domain_OSUMC_IT_CHECKBOX.Text.Trim()) == 1)
{
Domain_green_Check.Visible = true;
}
else if (Int32.Parse(XP_OSUWMC_IT_LBL.Text.Trim()) >= 1 && <=.9)
{
Domain_green_Check.Visible = true;
This is where im having the trouble
else if (Int32.Parse(XP_OSUWMC_IT_LBL.Text.Trim()) >= 1 && <=.9)
I need to make the image domain_green_check visible if another label Domain_OSUMC_IT_CHCEKBOX is between the values of .9 and 1
You need to fix your syntax and conert the string to decimal
decimal val = decimal.Parse(XP_OSUWMC_IT_LBL.Text.Trim());
else if (val > .9 && val < 1) //though this condition makes nosense since it will never evaluate to TRUE
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What I try to do, is for example if I write five numbers 1,2,3,4,5 after this it should print 5,4,3,2,1
int[] numbers = new int[5];
for (int i = 0; i < numbers.Length ; i++)
{
Console.Write("");
numbers[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < numbers.Length; i++)
{
}
If you need just to print them in a reverse order, but you want to keep them stored as you inserted them, change the second loop like this:
for (int i=numbers.Length-1; i >= 0; i--){
Console.WriteLine(numbers[i]);
}
You can print the array with a reverse loop as in the previous answer, or you can do that in a single line:
Console.WriteLine(string.Join(",", numbers.Reverse()));