How to iterate the number in a while loop that allows the user to enter a number, and that number determines how many times the loop will execute for even number?
Welcome to the community
You can give the input given by the user in while loop properties max iterations
In condition give evennunberchecknumber mod 2 == 0
So as max iteration is number given by user it iterated for those many times
And as condition is checking for x mod 2 ==0 only even numbers will be iterated
Hope this helps
Cheers
Hi,
Can you try the following sample?
not(Int32.TryParse(objInput.ToString,New Int32) AndAlso Int32.Parse(objInput.ToString) Mod 2 =0)
Sample
Sample20231116-1L.zip (2.7 KB)
Regards,
Hi @Sobiya_Ali
Input Dialog (Title: "Enter Number", Label: "Please enter the number of iterations", Result: UserInput)
While (UserInput > 0)
If (UserInput Mod 2 = 0) // Check if the iteration number is even
// Your activities to be executed in each iteration
End If
Assign UserInput = UserInput - 1 // Decrement the iteration count
End While
Hi @Sobiya_Ali
→ Drag and drop the “Input Dialog” activity into your workflow.
→ Set the properties of the “Input Dialog” to prompt the user to enter a number. Store the user input in a variable, let’s say userInput.
→ Drag and drop the “While” activity into your workflow.
→ Set the condition of the “While” activity to check if the userInput is an even number. You can use the following condition:
Int32.Parse(userInput) Mod 2 = 0
This condition checks if the entered number is even.
→ Inside the “While” loop, include the activities that you want to execute. These activities will repeat as long as the user enters an even number.
Thank you
Hi @Sobiya_Ali
You can try this logic
userInput = InputDialog(“Enter the number of iterations for even numbers:”)
iterations = Int32.Parse(userInput)
counter = 0
While counter < iterations
If counter Mod 2 = 0
Then
// Your actions here
Else
// Your actions here
counter = counter + 1
Hope this helps
Thanks for replying.
For above suggestions if user input is 10 so output is like 2,4,6,8,10 but I want the output that based on user input number determines how many times the loop will execute for even number for example if user input is 8 so output should be 2,4,6,8,10,12,16,18 and if its 10 so output should be 2,4,6,8,10,12,14,16,18,20.
Can you please advice what to add in logic to get the output?
Thanks.
Hi @Sobiya_Ali ,
Could you maybe check with the below implementation :
Enumerable.Range(2,10*2).Where(Function(x)x Mod 2 =0).ToArray
Here, you could replace the value 10 with the variable count received from User Input.