pascal repeat的用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pascal repeat的用法相关的知识,希望对你有一定的参考价值。

参考技术A 用法:
repeat
...
until
布尔表达式=true;
即repeat语句当until后的布尔表达式为真时终结循环。
实例:
begin
...
i:=1;s:=0;
repeat
inc(s,i);
inc(i);
until
i>100;
writeln(s);
...
end.
计算1+2+3+4+...+99+100=?
附:inc(s);相当于s:=s+1;
inc(s,i);相当于s:=s+i;
参考技术B 一、关于for
循环次数是已知的,用for循环省事。
如:把"hello"连写10遍。
for
i:=1
to
10
do
write('hello
');
二、关于while
如果事先不能确定循环的次数,循环开始需要依靠其它条件得到满足才能启动就得用while
如:当我键入'y'时,就开始不停写"hello",
program
testwhile;
var
a:char;
bengin
read(a);
while
a='y'
do
write('hello');
end.
输入的字符不是y,程序直接结束。如果是y,那就......,
哈哈
三、关于repeat
如果循环的次数不能事先确定,但循环一定要进行(至少也要进行一遍),直到满足了某种条件,才能停止,就得用repeat
如等我键入'n',就可以停止写"hello"了。
program
testrepeat;
var
a:char;
bengin
repeat
readln(a);
write('hello');
until
a='n';
end.
运行时需要键入一个字符,如果这个字符不是n,就会再次要你键入,直接你厌烦了,输入n,才能消停,哈哈。
参考技术C 格式:
repeat
……被循环执行的语句;
until
……循环结束条件;
执行时会重复执行被循环执行的语句,直到循环结束条件为真时退出循环。
例如,执行下列程序:
var
i:integer;
begin
i:=0;
repeat
i:=i+1;
write(i);
until
i=10;
writeln;
end.
会得到输出结果:
12345678910

repeater灵活运用repeater的commmand用法如何不用repeater展示数据

实体类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// gouwu 的摘要说明
/// </summary>
public class gouwu
{
    public gouwu()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public int ids { get; set; }
    public string pic { get; set; }
    public string name { get; set; }
    public decimal nowprice { get; set; }
    public decimal oldprice { get; set; }
    public string context { get; set; }


}

数据访问类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/// <summary>
/// gouwudata 的摘要说明
/// </summary>
public class gouwudata
{
    SqlConnection conn = null;
    SqlCommand cmd = null;
    public gouwudata()
    {
        conn = new SqlConnection("server=.;database=data0928;user=sa;pwd=123");
        cmd = conn.CreateCommand();
    }
    public List<gouwu> select()
    {
        List<gouwu> glist = new List<gouwu>();
        cmd.CommandText = "select*from gouwu";
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                gouwu g = new gouwu();
                g.ids = Convert.ToInt32(dr[0]);
                g.pic = dr[1].ToString();
                g.name = dr[2].ToString();
                g.nowprice = Convert.ToDecimal(dr[3]);
                g.oldprice = Convert.ToDecimal(dr[4]);
                g.context = dr[5].ToString();

                glist.Add(g);
            }
        
        }

        conn.Close();
        return glist;
    }
    public void delete(int ids)
    {
        cmd.CommandText = "delete from gouwu where ids=‘"+ids+"";
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
    
    }
}

 

aspx里:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style>
        * {
        padding:0px;
        margin:0px;
        }

        #header {
            width:100%;
            height:80px;
            background-color:navy;
            position:relative;
        }
        #footer {
        width:100%;
        height:80px;
        background-color:black;
        position:relative;
        }
        #items {
        width:80%;
        margin-left:10%;
        position:relative;       
      
        }
        .item {
        position:relative;
        width:23.5%;
        margin-left:0.5%;
        margin-right:0.5%;
        height:295px;
        margin-top:5px;
        border:solid 1px;
        float:left;
        margin-bottom:5px;
        }
        .item img {
            position:relative;
            width:100%;
            height:60%;
            }
        .itemname {
        position:relative;
        width:80%;
        margin-left:10%;
        font-size:18px;
        }
        .itemprice {
        position:relative;
        width:100%;
        color:red;
        text-align:right;
        font-size:18px;
        }
            .itemprice span {
            font-size:12px;
            text-decoration:line-through;            
            }
        .itemcon {
            position:relative;
            width:90%;
            margin-left:5%;
        }

    </style>

</head>
<body>
    <form id="form1" runat="server">
    <div id="header"></div>
    <div id="items">
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <div class="item">
            <img src="<%#Eval("pic") %>" />
            <div class="itemname"><%#Eval("name") %></div>
            <div class="itemprice">价格:<%#Eval("nowprice") %><span><%#Eval("oldprice") %></span></div>
            <div class="itemcon"><%#Eval("context") %></div> 
            <asp:Button ID="Button1" runat="server" Text="删除" CommandName="delete" CommandArgument=<%#Eval("ids") %> /><%--repeater的command方法--%>              
            </div>

            </ItemTemplate>


        </asp:Repeater>
        <div style="clear:both"></div>//使高度自适应
    </div>
    <div id="footer"></div>
   
    </form>
</body>
</html>

cs里:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Repeater1.DataSource = new gouwudata().select();
            Repeater1.DataBind();
        }
        Repeater1.ItemCommand += Repeater1_ItemCommand;

    }

    void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete")//repeater的command方法
        {
            new gouwudata().delete(Convert.ToInt32(e.CommandArgument));//repeater的command方法
            Repeater1.DataSource = new gouwudata().select();//删除后及时刷新数据
            Repeater1.DataBind();
        }
    }
}

 

 

如何不用repeater展示数据:

aspx中:用literal

<body style="font-family: 微软雅黑;">
    <form id="form1" runat="server">
        <div id="header">
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
        <div id="items">

            <asp:Literal ID="Literal1" runat="server"></asp:Literal>

            <div style="clear: both;"></div>
        </div>

        <div id="footer"></div>
    </form>
</body>

cs中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Literal1.Text = DataBind();
        }


    }

    

    public string DataBind()
    {
        string end = "";

        List<gouwu> glist = new gouwuData().Select();

        foreach (gouwu g in glist)
        {
            if (g.name == "猕猴桃")
            {
                continue;
            }

            end += "<div class=\"item\">";
            end += "<img src=\"" + g.pic + "\" />";
            end += " <div class=\"item-name\">" + g.name + "</div>";
            end += "<div class=\"item-price\">价格:" + g.nowPrice + "<span>" + g.oldPrice + "</span></div>";
            end += "<div class=\"item-context\">" + g.context + "</div>";
            end += "<a href=\"Delete.aspx?id=" + g.ids + "\">删除</a>";
            end += "</div>";
        }
        return end;
    }




}

 

以上是关于pascal repeat的用法的主要内容,如果未能解决你的问题,请参考以下文章

ng-repeat用法

repeater的command事件用法

2017-5-22 Repeater的Command用法

python中repeat函数用法

repeater灵活运用repeater的commmand用法如何不用repeater展示数据

Repeater用法