Using loops in TEAL

Hi there! Is there a way to slide transactions contained in an atomic group using loop? The code would be the following but I am getting strconv.ParseUint: parsing “VAR_TEMP_COUNTER”: invalid syntax when I try to use a variable.

#pragma version 6
	int 0
loop:
	int 1
	+
	store 0

	int VAR_TMPL_COUNTER	
	load 0

	dup
	
	gtxn VAR_TMPL_COUNTER RekeyTo
	global ZeroAddress
	==
	
	global Groupsize
	<=
bnz loop

Where I am in wrong? Thanks as usual :slightly_smiling_face:

Here’s an example smart contract which will create a number of inner transactions within the same group based on the size of the fee used. For example if you pay 1000 microAlgo it will call the application and produce zero inners. If you pay 3000 microAlgo it will call the application and produce an inner transaction group of 2 payment transactions.

Hope this helps?

#pragma version 6

// Number of iterations (based on fee size)
txn Fee
global MinTxnFee
-
global MinTxnFee
/
store 0

// If zero, no itxns
load 0
bz end

// Begin itxns
itxn_begin
loop:
  // Decrement
  load 0
  int 1
  -
  store 0

  // Payment transaction
  int pay
  itxn_field TypeEnum

  // To sender
  txn Sender
  itxn_field Receiver

  // Outer pays fee
  int 0
  itxn_field Fee

  load 0
  bz no_more
  itxn_next
  b loop

no_more:
  itxn_submit

end:
  int 1
1 Like

Thank you @nullun ! :muscle: