#### RealGambler

exercise 1:
@echo off

setlocal enabledelayedexpansion

rem create list

set a[0]=michael

set a[1]=pique

set a[2]=elias
set a[3]=george

set a[4]=tobias

rem based on the table above and using

rem command for create the following content display:

michael tobias

pique george

elias elias

george pique

tobias michael

exercise 2:

make the (for) command work properly with the (reverse) command

@echo off

setlocal enabledelayedexpansion

rem create list

set a[0]=1

set a[1]=2

set a[2]=3

set a[3]=4

set a[4]=5

for /L %%x in (0,1,4) do (

set /a "reverse=4-%%x"

echo !a[%%reverse]!

rem echo !reverse!

)

pause

#### Kuncode

Here is the corrected version of both exercises:

Exercise 1:

Code:
``````@echo off
setlocal enabledelayedexpansion

rem create list
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias

rem based on the table above and using (for) command to create the following content display:
for /L %%x in (0,1,4) do (
set /a "y=%%x+1"
if !y! gtr 4 (set y=0)
echo !a[%%x]! !a[!y!]!
)
pause``````

Exercise 2:

Code:
``````@echo off
setlocal enabledelayedexpansion

rem create list
set a[0]=1
set a[1]=2
set a[2]=3
set a[3]=4
set a[4]=5

rem using the (for) command with the (reverse) option to display the elements in reverse order
for /L %%x in (4,-1,0) do (
echo !a[%%x]!
)
pause``````

#### RealGambler

First of all....REALLY THANK YOU for the reply,
the second exercise is perfect !
the first one shows me that:
michael y
pique y
elias y
george y
tobias y
Press any key to continue...
Question: How i can do this ? :
michael tobias

pique george

elias elias

george pique

tobias michael ?
BTW THANKS AGAIN FOR THE REPLY

#### Kuncode

First of all....REALLY THANK YOU for the reply,
the second exercise is perfect !
the first one shows me that:
michael y
pique y
elias y
george y
tobias y
Press any key to continue...
Question: How i can do this ? :
michael tobias

pique george

elias elias

george pique

tobias michael ?
BTW THANKS AGAIN FOR THE REPLY
Code:
``````@echo off
setlocal enabledelayedexpansion

rem create list
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias

rem based on the table above and using (for) command to create the following content display:
for /L %%x in (0,1,4) do (
set /a "y=%%x+1"
if !y! gtr 4 (set y=0)
echo !a[%%x]! y
)
pause``````

#### RealGambler

Sorry to bother...now it only shows me this, i try it but i can't find a solution
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias

#### Kuncode

Sorry to bother...now it only shows me this, i try it but i can't find a solution
set a[0]=michael
set a[1]=pique
set a[2]=elias
set a[3]=george
set a[4]=tobias
You can achieve the desired output by modifying the code as follows:

@echo off setlocal enabledelayedexpansion

rem create list set a[0]=michael set a[1]=pique set a[2]=elias set a[3]=george set a[4]=tobias

rem based on the table above and using (for) command to create the following content display: for /L %%x in (0,1,4) do ( set /a "y=(%%x+2) % 5" echo !a[%%x]! !a[!y!]! ) pause

This code calculates the next index (y = (x + 2) % 5) in each iteration, which will result in the desired output. The final output will be:

michael tobias

pique george

elias elias

george pique

tobias michael

#### RealGambler

Please because probably im doing something wrong ....can you send me dm on (e-mail address removed) ? pls

## Ask a Question

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

### Members online

No members online now.