Home > other >  batch script to add a number next to each prime number
batch script to add a number next to each prime number

Time:08-06

I want to create a script that does the action: Enter first number then last number,And what is obtained is that for each number child, numbers from 1 to 3 will appear


first number=1

last number=2

What you get is this:

  • 1 1
  • 1 2
  • 1 3
  • 2 1
  • 2 2
  • 2 3

What I managed is this file

@echo off
set /p F=first number:
set /p L=last number:

setlocal ENABLEDELAYEDEXPANSION
FOR /L %%A IN (%F%,1,%L%) DO (
set /A result=%%A %% 3
echo %%A !result!
)

But the result is not good enough

enter image description here

CodePudding user response:

What you need are nested for loops:

@echo off
set /p F=first number:
set /p L=last number:

setlocal ENABLEDELAYEDEXPANSION
FOR /L %%A IN (%F%,1,%L%) DO (
  for /L %%B in (1,1,3) do (
    echo %%A %%B
  )
)
  • Related